home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_print.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-09-17  |  3.9 KB  |  136 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28. #include "system_headers.h"
  29.  
  30. static char initialdrawer[TEXT_LENGTH];
  31. static char initialfile[FILENAME_LENGTH] = "prt:";
  32. static char printfilename[FILENAME_LENGTH] = "prt:";
  33.  
  34. ULONG MyRequest( UBYTE *gadgets,
  35.                  UBYTE *fmt, ... )
  36. {
  37.     ULONG result = 0;
  38.     UBYTE *buf;
  39.  
  40.     if (buf = tbAllocVecPooled(globalPool, TMP_STRING_LENGTH)) {
  41.         va_list args;
  42.         struct EasyStruct myreqES;
  43.         struct Window *myreq_window;
  44.  
  45.         va_start(args,fmt);
  46.         _vsnprintf(buf, TMP_STRING_LENGTH, fmt, args);
  47.         va_end(args);
  48.  
  49.         get (WI_Main, MUIA_Window_Window, &myreq_window);
  50.  
  51.         myreqES.es_StructSize = sizeof(struct EasyStruct);
  52.         myreqES.es_Flags = 0;
  53.         myreqES.es_Title = "Scout Request";
  54.         myreqES.es_TextFormat = buf;
  55.         myreqES.es_GadgetFormat = gadgets;
  56.         result = EasyRequest (myreq_window, &myreqES, NULL);
  57.  
  58.         tbFreeVecPooled(globalPool, buf);
  59.     }
  60.  
  61.     return result;
  62. }
  63.  
  64. static BOOL FileRequest (void) {
  65.    struct   Window         *aslfr_window = NULL;
  66.    struct   FileRequester  *requester;
  67.    BOOL     result = FALSE;
  68.  
  69.    get (WI_Main, MUIA_Window_Window, &aslfr_window);
  70.  
  71.    if (aslfr_window) {
  72.       if (requester = AllocAslRequestTags (ASL_FileRequest,
  73.                       ASLFR_Window, aslfr_window,
  74.                       ASLFR_PrivateIDCMP, TRUE,
  75.                       ASLFR_SleepWindow, TRUE,
  76.                       NULL)) {
  77.  
  78.          result = AslRequestTags (requester,
  79.                   ASLFR_TitleText, "Choose file or printer!",
  80.                   ASLFR_InitialDrawer, initialdrawer,
  81.                   ASLFR_InitialFile, initialfile,
  82.                   ASLFR_DoSaveMode, TRUE,
  83.                   NULL);
  84.  
  85.          stccpy(initialdrawer, requester->fr_Drawer, sizeof(initialdrawer));
  86.          stccpy(initialfile, requester->fr_File, sizeof(initialfile));
  87.  
  88.          stccpy(printfilename, initialdrawer, sizeof(printfilename));
  89.          AddPart(printfilename, initialfile, sizeof(printfilename));
  90.  
  91.          FreeAslRequest (requester);
  92.       }
  93.    }
  94.    return (result);
  95. }
  96.  
  97. BPTR PrintHandle;
  98. LONG PrintHandleMode = MODE_NEWFILE;
  99.  
  100. BPTR HandlePrintStart (char *filename) {
  101.    PrintHandle = (BPTR)NULL;
  102.  
  103.    if (AP_Scout) {
  104.       if ((! filename) && (! FileRequest()))
  105.          return ((BPTR)NULL);
  106.       ApplicationSleep(TRUE);
  107.    } else if ((! filename) || (filename[0] == '\0')) {
  108.       return (Output());
  109.    }
  110.    if (filename) {
  111.       stccpy(printfilename, filename, sizeof(printfilename));
  112.    }
  113.    if (! (PrintHandle = Open (printfilename, PrintHandleMode))) {
  114.       if (PrintHandleMode == MODE_OLDFILE) {
  115.          PrintHandle = Open (printfilename, MODE_NEWFILE);
  116.       }
  117.       if (! PrintHandle)
  118.          MyRequest ("Continue", "Couldn't open file \'%s\'!", printfilename);
  119.    }
  120.    if (PrintHandle) {
  121.       Seek (PrintHandle, 0, OFFSET_END);
  122.    }
  123.    return (PrintHandle);
  124. }
  125.  
  126. void HandlePrintStop (void) {
  127.    if (AP_Scout) {
  128.       ApplicationSleep(FALSE);
  129.    }
  130.    if (PrintHandle) {
  131.       Close (PrintHandle);
  132.    }
  133. }
  134.  
  135.  
  136.